********************************************************************************
* Voters
********************************************************************************

use dataset_voters, clear

gen wells = exp(lnwells) - 1
gen ihswells = log(wells + (wells^2 + 1)^(0.5))
replace dwells = log(dwells + 1)

gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post
tabulate year, gen(year_)

eststo clear
eststo: reg turnout lnwells year_2 year_3 year_4 year_5, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout ihswells year_2 year_3 year_4 year_5, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout dwells year_2 year_3 year_4 year_5, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

keep if highfracking == 1
eststo: reg turnout lnwells year_2 year_3 year_4 year_5, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout ihswells year_2 year_3 year_4 year_5, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout dwells year_2 year_3 year_4 year_5, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

label variable lnwells "Log wells"
label variable ihswells "Inverse hyperbolic sine wells"
label variable dwells "Log change in wells"

#delimit;

esttab 
	using "_output/tableA5a.tex",
		replace
		booktabs
		order(lnwells ihswells)
		drop(*year* _cons)
		cells(b(fmt(3) star) se(par))
		compress
		label
		gap
		collabels(none)
		nomtitles
		width(\linewidth)
		mgroups(
			"All states" "High-fracking states", 
			pattern(1 0 0 1 0 0)
			prefix(\multicolumn{@span}{c}{) suffix(})
			span erepeat(\cmidrule(lr){@span})
		)	
		stats(
			YFE
			ZFE
			N_clust
			N
			,
				label(
					"Year fixed effects"
					"Zip code fixed effects" 
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)
		;
	
#delimit cr

********************************************************************************
* Donors
********************************************************************************

use dataset_donors, clear

gen wells = exp(lnwells) - 1
gen ihswells = log(wells + (wells^2 + 1)^(0.5))
replace dwells = log(dwells + 1)

gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post

drop if mi(ltotamount)
tabulate year, gen(year_)

eststo clear
eststo: areg ltotamount lnwells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(zipcode) cl(zipcode)
eststo: areg ltotamount ihswells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount dwells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

keep if highfracking == 1
eststo: areg ltotamount lnwells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(zipcode) cl(zipcode)
eststo: areg ltotamount ihswells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount dwells year_2 year_3 year_4 year_5 ///
	year_6 year_7 year_8, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

label variable lnwells "Log wells"
label variable ihswells "Inverse hyperbolic sine wells"
label variable dwells "Log change in wells"

#delimit;

esttab 
	using "_output/tableA5b.tex"
	,
		replace
		booktabs
		order(lnwells ihswells)
		cells(b(fmt(3) star) se(par))
		drop(*year* _cons*)
		compress
		label
		gap
		width(\linewidth)
		collabels(none)
		nomtitles
		mgroups(
			"All states" "High-fracking states", 
				pattern(1 0 0 1 0 0)
				prefix(\multicolumn{@span}{c}{) suffix(})
				span erepeat(\cmidrule(lr){@span})
		)
		stats(
			YFE
			ZFE
			N_clust
			N,
				label(
					"Year fixed effects"
					"Zip code fixed effects"
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)	
		star(* 0.05 ** 0.01 *** 0.001)
		;
		
#delimit cr

********************************************************************************
* End
********************************************************************************
